Weapons = {}
Weapons.Primary = {}
Weapons.Secondary = {}

Weapons.Primary.Assassin = {[1] = "weapon_mdm_glock",[2] = "weapon_mdm_mac_10",[3] = "weapon_mdm_mp5",[4] = "weapon_mdm_ump_45"}
Weapons.Secondary.Assassin = {[1] = "weapon_mdm_usp_45"}

Weapons.Primary.Marksman = {[1] = "weapon_mdm_m4a1"}
Weapons.Secondary.Marksman = {[1] = "weapon_mdm_glock",[3] = "weapon_mdm_usp_45"}

Weapons.Primary.Soldier = {[1] = "weapon_mdm_ump_45",[2] = "weapon_mdm_mp5",[3] = "weapon_mdm_galil",[4] = "weapon_mdm_m249",[5] = "weapon_mdm_ak47"}
Weapons.Secondary.Soldier = {[1] = "weapon_mdm_glock",[2] = "weapon_mdm_frag_grenade",[3] = "weapon_mdm_usp_45",[4] = "weapon_mdm_mac_10",[5] = "weapon_mdm_sticky_grenade"}

Weapons.Primary.Support = {[1] = "weapon_mdm_mp5",[3] = "weapon_mdm_m3",[4] = "weapon_mdm_m249",[5] = "weapon_mdm_xm1014"}
Weapons.Secondary.Support = {[1] = "weapon_mdm_glock",[3] = "weapon_mdm_usp_45",[5] = "weapon_mdm_frag_grenade"}


function RequestLoadout(ply,cmd,args)
	local class = ply:GetNWString("class")
	
	if class == "assassin" then
		if args[1] != "_" then
			for k,v in pairs(Weapons.Primary.Assassin) do
				if v == args[1] and k <= ply:GetNWInt("assassinlvl") then
					SetLoadout(ply,class,1,args[1])
				end
			end
		end
		if args[2] != "_" then
			for k,v in pairs(Weapons.Secondary.Assassin) do
				if v == args[2] and k <= ply:GetNWInt("assassinlvl") then
					SetLoadout(ply,class,2,args[2])
				end
			end
		end
	end
	
	if class == "marksman" then
		if args[1] != "_" then
			for k,v in pairs(Weapons.Primary.Marksman) do
				if v == args[1] and k <= ply:GetNWInt("marksmanlvl") then
					SetLoadout(ply,class,1,args[1])
				end
			end
		end
		if args[2] != "_" then
			for k,v in pairs(Weapons.Secondary.Marksman) do
				if v == args[2] and k <= ply:GetNWInt("marksmanlvl") then
					SetLoadout(ply,class,2,args[2])
				end
			end
		end
	end
	
	if class == "soldier" then
		if args[1] != "_" then
			for k,v in pairs(Weapons.Primary.Soldier) do
				if v == args[1] and k <= ply:GetNWInt("soldierlvl") then
					SetLoadout(ply,class,1,args[1])
				end
			end
		end
		if args[2] != "_" then
			for k,v in pairs(Weapons.Secondary.Soldier) do
				if v == args[2] and k <= ply:GetNWInt("soldierlvl") then
					SetLoadout(ply,class,2,args[2])
				end
			end
		end
	end
	
	if class == "support" then
		if args[1] != "_" then
			for k,v in pairs(Weapons.Primary.Support) do
				if v == args[1] and k <= ply:GetNWInt("supportlvl") then
					SetLoadout(ply,class,1,args[1])
				end
			end
		end
		if args[2] != "_" then
			for k,v in pairs(Weapons.Secondary.Support) do
				if v == args[2] and k <= ply:GetNWInt("supportlvl") then
					SetLoadout(ply,class,2,args[2])
				end
			end
		end
	end
end

concommand.Add("dm_req_loadout",RequestLoadout)

function SetLoadout(ply,class,wepnum,wep)
	local class = ply:GetNWString("class")
	
	if class == "assassin" then
		if !ply.Weapons.Assassin then ply.Weapons.Assassin = {"",""} end
		ply.Weapons.Assassin[wepnum] = wep
	end
	
	if class == "marksman" then
		if !ply.Weapons.Marksman then ply.Weapons.Marksman = {"",""} end
		ply.Weapons.Marksman[wepnum] = wep
	end
	
	if class == "soldier" then
		if !ply.Weapons.Soldier then ply.Weapons.Soldier = {"",""} end
		ply.Weapons.Soldier[wepnum] = wep
	end
	
	if class == "support" then
		if !ply.Weapons.Support then ply.Weapons.Support = {"",""} end
		ply.Weapons.Support[wepnum] = wep
	end
	ply:SetPData("weapons",glon.encode(ply.Weapons))
	print("DM: "..ply:Nick().." updated their loadout ("..class..", "..wepnum..", "..wep..")")
end